package com.liuqianfei.markme;

import com.liuqianfei.markme.rules.IAction;
import com.liuqianfei.markme.rules.Ruler;
import com.liuqianfei.markme.rules.StateCore;
import com.liuqianfei.markme.rules.core.BlockAction;
import com.liuqianfei.markme.rules.core.InlineAction;
//import com.liuqianfei.markme.rules.core.SmartquotesAction;

import java.util.List;

/**
 * internal
 * 
 * <p>Top-level rules executor. Glues block/inline parsers and does intermediate
 * transformations.
 **/
public class ParserCore implements IParser
{
    /**
     * {@link Ruler} instance. Keep configuration of core rules.
     */
    Ruler ruler;
    
    public ParserCore()
    {
        ruler = new Ruler();

        // block
        ruler.push("block", new BlockAction(), null);

        // inline
        ruler.push("inline", new InlineAction(), null);

        // smartquotes
//        ruler.push("smartquotes", new SmartquotesAction(), null);

        // TODO other
    }
    
    /**
     * Executes core chain rules.
     */
    public void process(StateCore state)
    {
        List<IAction> rules = this.ruler.getRules("");
        
        // FIXME: 2016/12/14
        if (null == rules)
            return;
        
        for (IAction rule : rules)
        {
            rule.parse(state, false, 0, 0);
        }
    }

    @Override
    public Ruler getRuler()
    {
        return ruler;
    }

    @Override
    public Ruler getRuler2()
    {
        return null;
    }
}
